using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace MVCFramework
{

    #region UnitPropertyDescriptor

    /// <summary>
    ///  enhances the base class by transforming 
    /// from the resource.
    /// </summary>
    public class UnitPropertyDescriptor : PropertyDescriptor
    {
        public override TypeConverter Converter
        {
            get
            {
                return new UnitTypeConverter (this);
            }
        }
        private PropertyDescriptor basePropertyDescriptor;

        public UnitPropertyDescriptor(PropertyDescriptor basePropertyDescriptor)
            : base(basePropertyDescriptor)
        {
            this.basePropertyDescriptor = basePropertyDescriptor;
        }

        public override AttributeCollection Attributes
        {
            get
            {
                return basePropertyDescriptor.Attributes;
            }
        }

        public override bool CanResetValue(object component)
        {
            return basePropertyDescriptor.CanResetValue(component);
        }

        public override Type ComponentType
        {
            get { return basePropertyDescriptor.ComponentType; }
        }

        public override string DisplayName
        {
            get
            {

                return basePropertyDescriptor.DisplayName;
            }
        }

        public override string Description
        {
            get
            {

                return basePropertyDescriptor.Description;
            }
        }

        public override object GetValue(object component)
        {
            return this.basePropertyDescriptor.GetValue(component);
        }

        public override bool IsReadOnly
        {
            get { return this.basePropertyDescriptor.IsReadOnly; }
        }

        public override string Name
        {
            get { return this.basePropertyDescriptor.Name; }
        }

        public override Type PropertyType
        {
            get { return this.basePropertyDescriptor.PropertyType; }
        }

        public override void ResetValue(object component)
        {
            this.basePropertyDescriptor.ResetValue(component);
        }

        public override bool ShouldSerializeValue(object component)
        {
            return this.basePropertyDescriptor.ShouldSerializeValue(component);
        }

        public override void SetValue(object component, object value)
        {
            this.basePropertyDescriptor.SetValue(component, value);
        }
    }
    #endregion


    public  class UnitTypeConverter : System .ComponentModel .TypeConverter 
    {
        PropertyDescriptor baseDescrip;
        string unitType;

        public UnitTypeConverter(PropertyDescriptor descriptor)
        {
            this.baseDescrip = descriptor;
            
        }
       public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, Type sourceType)
       {
           return base.CanConvertFrom(context, sourceType);
       }

       public override bool CanConvertTo(System.ComponentModel.ITypeDescriptorContext context, Type destinationType)
       {
           return base.CanConvertTo(context, destinationType);
       }

       public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
       {
           return base.ConvertFrom(context, culture, value);
       }

       public override object ConvertTo(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
       {
           return base.ConvertTo(context, culture, value, destinationType);
       }
    }


    public class UnitConverterAttribute : System.Attribute
    {
        string UnitType;
        public UnitConverterAttribute(string unitType)
        {
            this.UnitType = unitType;
        }
    }

}
